package com.sunny.ynhz.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunny.ynhz.R;
import com.sunny.ynhz.api.NetUrl;
import com.sunny.ynhz.utils.DensityUtil;
import com.sunny.ynhz.utils.ScreenUtils;

import java.util.List;

/**
 * Created by huhuan123 on 2018/6/1.
 */

public class OrganizationPhotoAdapter extends RecyclerView.Adapter<OrganizationPhotoAdapter.ViewHolder> {
    Context context;
    List<String> mlist;

    public OrganizationPhotoAdapter(Context context, List<String> mlist) {
        this.context = context;
        this.mlist = mlist;
    }

    @Override
    public OrganizationPhotoAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_organization_photo, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ViewGroup.LayoutParams layoutParams = holder.imageView.getLayoutParams();
        float v = (ScreenUtils.getScreenWith(context) - DensityUtil.dip2px(context, 10) * 2 - 20) / 2;
        layoutParams.width = (int) v;
        layoutParams.height = (int) v;
        holder.imageView.setLayoutParams(layoutParams);
        Glide.with(context).load(NetUrl.baseImageUrl + mlist.get(position))
                .placeholder(R.mipmap.ic_deafult)
                .error(R.mipmap.ic_deafult)
                .centerCrop()
                .into(holder.imageView);

    }


    @Override
    public int getItemCount() {
        return mlist.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        ImageView imageView;

        //在布局中找到所含有的UI组件
        public ViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.img_photo);

        }
    }
    //
}
